package com.wosai.register.service;


import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
import org.springframework.stereotype.Service;


@Service
public class SecurityService {
    
    @Autowired
    private AuthenticationManager authenticationManager;

    
    public String login(HttpServletRequest request, String username, String password) throws AuthenticationException{
        UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);
        authRequest.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));

        Authentication auth= this.authenticationManager.authenticate(authRequest);
        return com.wosai.register.util.SecurityUtil.encodeToken(username, password);

    }
    
    
}
